﻿{extend name="public:base" /}

{block name="content"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox search-form">
                <div class="ibox-content">
                    <div class="row">
                        <div class="col-sm-2 m-b-xs">
                            <input placeholder="请输入姓名" type="text" name="username" value="{:input('username')}" class="form-control form-control-sm">
                        </div>
                        <div class="col-sm-2 m-b-xs">
                            <input placeholder="请输入手机号" type="text" name="mobile" value="{:input('mobile')}" class="form-control form-control-sm">
                        </div>
                        <div class="col-sm-2 m-b-sm">
                            <div class="input-group">
                                <button type="button" class="btn btn-primary btn-lg screen-btn">搜索</button>
                            </div>
                        </div>
                    </div>
                    <div class="table-responsive">
                        <table class="table table-striped">
                            <thead>
                            <tr>
                                <th>姓名</th>
                                <th>手机号</th>
                                <th>状态</th>
                                <th>审核状态</th>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            {volist name="list" id="vo"}
                            <tr>
                                <td>{$vo.username}</td>
                                <td>{$vo.mobile}</td>
                                <td>{$vo.status == 1 ? '正常' : '禁用'}</td>
                                <td>{$vo.examine|doExamine}</td>
                                <td>{$vo.create_time|timeFormat}</td>
                                <td class="project-actions">
                                    <a href="{:url('twoUserList', ['pid' => $vo.id])}" class="btn btn-white btn-sm"><i class="iconfont icon-list"></i> 城市合伙人
                                    </a>
                                    <a href="{:url('threeUserList', ['one_pid' => $vo.id])}" class="btn btn-white btn-sm"><i class="iconfont icon-list"></i> 分享官
                                    </a>
                                    <a href="javascript:void(0)" onclick="openModel({$vo.id}, {$key})" data-toggle="modal" data-target="#myModal" class="btn btn-white btn-sm"><i class="iconfont icon-edit"></i> 关系转移
                                    </a>
                                    <a href="{:url('doOneUser', ['id' => $vo.id])}" class="btn btn-white btn-sm"><i class="iconfont icon-edit"></i> 编辑
                                    </a>
                                    <a href="{:url('delOneUser', ['id' => $vo.id])}" class="btn btn-white btn-sm ajax-del"><i class="iconfont icon-trash"></i> 删除
                                    </a>
                                </td>
                            </tr>
                            {/volist}
                            </tbody>
                        </table>
                        {if !empty($list)}{$list->render()}{/if}
                    </div>

                </div>
            </div>
        </div>

    </div>
</div>


<div class="modal inmodal" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content animated flipInY">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title">关系转移</h4>
            </div>
            <div class="modal-body">
                <div id="list">
                    {volist name="list" id="vo"}
                    <div onclick="changeUser(this, {$vo.id})">{$vo.username}</div>
                    {/volist}
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="confirmChange()">确认转移</button>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="css"}
<style>
  #list .active {
    color: #fff;
    background: #1ab394;
  }
</style>
{/block}

{block name="js"}
<script>
    var old_user_id = 0;
    var new_user_id = 0;

    function openModel(user_id, key) {
        $('#list div').removeClass('active');
        old_user_id = user_id;
        new_user_id = user_id;
        $('#list div').eq(key).addClass('active');
    }

    function changeUser(that, user_id) {
        new_user_id = user_id;
        $('#list div').removeClass('active');
        $(that).addClass('active');
    }

    function confirmChange() {
        $.post('/admin/manage/changeRelation', {old_user_id, new_user_id}, function (res) {
            if (res.result == 1) {
                layer.msg(res.msg);
                setTimeout(() => {
                    window.location.reload();
                }, 1000)
            } else {
                layer.msg(res.msg);
            }
        }, 'JSON')
    }
</script>
{/block}

